<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>

        // redux 
        // redux-thunk

        let list = []

        function dispatch(action) {
            // 判断是否是对象
            if (typeof action === 'object') {
                console.log('已经是对象，可以执行下一步')
                // 判断是否有type属性
                if (action.type) {
                    console.log('success')
                } else {
                    throw Error('actions中必须有一个type属性')
                }
            } else {
                throw Error('actions必须是一个对象')
            }
        }

        // 保留原来的dispatch
        let oldDispatch = dispatch
        // 覆盖原来的dispatch
        dispatch = (action) => {
            if (typeof action === 'function') {
                console.log('可以接收函数了')
            } else {
                oldDispatch(action)
            }
        }

        dispatch((next) => {
            setTimeout(() => {
                list = [1, 2, 3, 4]
                next({ type: "INIT", list })
            }, 1000)
        })
        

    </script>
</body>
</html>